package com.LostAndFound.service;

import java.sql.SQLException;

import com.LostAndFound.dao.UserRegisterDao;
import com.LostAndFound.domain.User;
import com.LostAndFound.utils.DataSourceUtils;

public class UserRegisterService {
	UserRegisterDao dao = new UserRegisterDao();

	public boolean checkUsername(String username) {
		int row = 0;
		try {
			row = dao.checkUsername(username);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return row>0?true:false;
	}

	public boolean regeisterUser(User user) {
		boolean success = false;
		try {
			DataSourceUtils.startTransaction();
			dao.regeisterUser(user);
			success = true;
		} catch (SQLException e) {
			try {
				DataSourceUtils.rollback();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				DataSourceUtils.commitAndRelease();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return success;
	}

}
